package com.wenwei.sharebox.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.wenwei.sharebox.R;
import com.wenwei.sharebox.base.BaseActivity;
import com.wenwei.sharebox.base.Constant;
import com.wenwei.sharebox.bean.UserIdentityBean;
import com.wenwei.sharebox.bean.UserLoginBean;
import com.wenwei.sharebox.net.ApiManager;
import com.wenwei.sharebox.net.BaseSubscriber;
import com.wenwei.sharebox.utils.RogerSPUtils;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2017/7/10.
 */
public class UserWalletActivity extends BaseActivity {
    @Bind(R.id.base_title)
    TextView baseTitle;
    @Bind(R.id.ji_fen_tv)
    TextView jiFenTv;
    @Bind(R.id.ya_jin_tv)
    TextView yaJinTv;

    @Override
    public int setLayoutResourceId() {
        return R.layout.activity_wallet;
    }

    @Override
    protected void initView() {
        super.initView();
        baseTitle.setText("我的钱包");
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick({R.id.base_back, R.id.wallet_integral, R.id.wallet_ya_jing})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.base_back:
                finish();
                break;
            case R.id.wallet_integral:
                Bundle bundle = new Bundle();
                bundle.putInt("type",1);
                goActivity(mContext, TopUpActivity.class,bundle);
                break;
            case R.id.wallet_ya_jing:
                applyDeposit();
                break;
        }
    }


    @Override
    protected void initData() {
        super.initData();
        getUserInfo();
    }

    private BaseSubscriber<UserLoginBean> userInfoSubscriber;
    private void getUserInfo() {
        userInfoSubscriber = new BaseSubscriber<UserLoginBean>(mContext) {
            @Override
            public void onSuccess(UserLoginBean userLoginBean) {
                RogerSPUtils.putObject(mContext, Constant.SP_USER_LOGIN_RESULT, userLoginBean);
                jiFenTv.setText("积分：  "+userLoginBean.getProfile().getIntegralNum());
                yaJinTv.setText("押金：  "+userLoginBean.getProfile().getDeposit());
            }
        };
        ApiManager.getInstance().getUserInfo(userInfoSubscriber);
    }


    private BaseSubscriber<UserIdentityBean> depositSubscriber;
    private void applyDeposit(){
        depositSubscriber = new BaseSubscriber<UserIdentityBean>(mContext) {
            @Override
            public void onSuccess(UserIdentityBean userIdentityBean) {
                finish();
                showToast("提交申请成功，请耐心等待...");
            }
        };
        ApiManager.getInstance().applyDeposit(depositSubscriber);
    }
}
